﻿package manager
{
    import com.core.*;
    import com.sh.game.global.*;
    import com.sh.game.loader.*;
    import flash.display.*;
    import flash.events.*;
    import flash.system.*;
    import flash.utils.*;
    import morn.core.handlers.*;

    public class MainSwfLoader extends Object
    {
        private var _completeFunc:Function;
        private var _curFile:String = "";
        private var _byteLoader:Loader;
        private var _progress:IProgressBar;
        private var _totalCount:int = 0;
        private var _dataUrls:Array;

        public function MainSwfLoader(param1:Function)
        {
            this._dataUrls = ["assets/images/mornui/mainbottom.swf", "assets/images/mornui/common.swf"];
            this._totalCount = this._dataUrls.length;
            this._progress = ModelProxy.getValue("progress", "progressBar");
            this._completeFunc = param1;
            this._byteLoader = new Loader();
            this._byteLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.loadNext);
            this.loadNextData();
            return;
        }// end function

        private function loadNextData() : void
        {
            var _loc_1:Object = null;
            if (this._dataUrls && this._dataUrls.length > 0)
            {
                this._curFile = this._dataUrls.shift();
                _loc_1 = SceneProloaderManager.instance.getCache(SceneProloaderManager.TYPE_SWF);
                if (_loc_1 && _loc_1[this._curFile])
                {
                    this.urlloaded(_loc_1[this._curFile]);
                }
                else
                {
                    SceneProloaderManager.instance.noNeed[this._curFile] = true;
                    App.mloader3.loadBYTE(Config.getUrl(this._curFile), 0, new Handler(this.urlloaded), new Handler(this.progressHandler), null, false);
                }
            }
            else if (this._completeFunc != null)
            {
                this._completeFunc();
                App.mloader3.maxLoader = 2;
                this.dispose();
            }
            return;
        }// end function

        private function progressHandler(param1) : void
        {
            this._progress.progress(null, 1, param1 + this._totalCount - this._dataUrls.length - 1, this._totalCount, 105);
            return;
        }// end function

        private function dispose() : void
        {
            this._completeFunc = null;
            this._byteLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, this.loadNext);
            this._byteLoader.unloadAndStop(false);
            this._byteLoader = null;
            return;
        }// end function

        protected function loadNext(event:Event) : void
        {
            this.loadNextData();
            return;
        }// end function

        private function urlloaded(param1) : void
        {
            var _loc_2:* = param1;
            _loc_2.position = 0;
            var _loc_3:* = Config.mswfkey;
            var _loc_4:* = new ByteArray();
            new ByteArray().writeMultiByte(_loc_3, "utf8");
            var _loc_5:* = _loc_2.length / 2;
            _loc_2.position = _loc_5;
            var _loc_6:int = 0;
            while (_loc_6 < _loc_4.length)
            {
                
                _loc_2.writeByte(_loc_2[_loc_6 + _loc_5] ^ _loc_4[_loc_6]);
                _loc_6++;
            }
            this._byteLoader.loadBytes(_loc_2, new LoaderContext(false, ApplicationDomain.currentDomain));
            _loc_2.clear();
            return;
        }// end function

    }
}
